﻿using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using CustomControls.AboutControl;
using CustomControls.InheritedFrameworkControls;
using Helpers;
using Infrasturcture.Global.Controls.LobbyMap;
using Infrasturcture.TouchLibrary;
using MallInteractiveMap.DTO;
using TouchControls;
using TouchAction = TouchFramework.TouchAction;

namespace MallInteractiveMap
{
    public partial class MainWindow
    {
        private void RegisterSettingsButton()
        {
            FrameworkManager.RegisterElement(SettingsButton, false, new[] { TouchAction.Tap });
            FrameworkManager.RegisterElement(SettingsChangeLanguageButton, false, new[] { TouchAction.Tap });
            FrameworkManager.RegisterElement(SettingsAboutButton, false, new[] { TouchAction.Tap });
            SettingsChangeLanguageButton.Click += SettingsChangeLanguageButton_Click;
            SettingsAboutButton.Click += SettingsAboutButtonClick;
        }

        void SettingsAboutButtonClick(object sender, RoutedEventArgs e)
        {
            if (SettingsButton.IsChecked == false) return;
            SettingsButton.IsChecked = false;
            ShowDialog(new About());
        }

        void SettingsChangeLanguageButton_Click(object sender, RoutedEventArgs e)
        {
            if (SettingsButton.IsChecked == false) return;
            SettingsButton.IsChecked = false;
            Thread.CurrentThread.CurrentUICulture =
                Thread.CurrentThread.CurrentUICulture.Name == Constants.Culture.US ?
                new CultureInfo(Constants.Culture.Arabic) : new CultureInfo(Constants.Culture.US);

            InputLanguageManager.SetInputLanguage(this, Thread.CurrentThread.CurrentUICulture);
            ReloadApplication();
        }

        private void ReloadApplication()
        {
            WaitScreen.Show();
            Floors = new ObservableCollection<DTOFloor>(MapPresenter.GetFloors());
            MallName.Text = MapPresenter.GetMall().Name;
            ClearFloorList();
            LoadFloorList();
            HideKeyBoard();
            CurrentFloor = null;
            CurrentFloorTitle = string.Empty;
            ClearMaps(MapHolder, FrameworkManager);
            WaitScreen.Hide();
        }
    }
}
